package com.yoga.view;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.yoga.service.UserManageService;

public class UserManageView {
	UserManageService userManageService = new UserManageService();

	public void addNewUser(String... pms) {
		if (pms.length < 6)
			System.out.println("输入参数个数有误，请重新输入");
		else {
			char gender = pms[2].charAt(0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date;
			try {
				date = sdf.parse(pms[3]);
			} catch (ParseException e) {
				System.out.println("请输入合法的时间参数");
				return;
			}
			int userId = userManageService.addNewUser(pms[1], gender, date, pms[4], pms[5]);
			System.out.println("OK. " + pms[1] + "'s member id is " + userId);
		}

	}

	public void addNewCard(String... pms) {
		if (pms.length < 3)
			System.out.println("输入参数个数有误，请重新输入");
		else {
			char type = pms[2].charAt(0);
			if (type != 'T' && type != 'Y') {
				System.out.println("没有该种类会员卡！");
				return;
			}
			int userId = Integer.valueOf(pms[1]);
			if (userManageService.bindCard(userId, type)) {
				String typeName = type == 'T' ? "次卡" : "年卡";
				System.out.println("OK. A new " + typeName + " added to " + userId);
			}

		}
	}

	public void showHelpMessage() {
		System.out.println("该程序支持如下命令：");
		System.out.println("add-member: 增加一个新用户，格式为“add-member 姓名 性别（F女，M男，U未知） 生日 联系方式 住址”");
		System.out.println("add-card: 增加一张新卡给用户，格式为“add-card 用户ID 卡的类型（Y年卡，T次卡）”");
	}

	public void errorCmd() {
		System.out.println("无效命令，请输入“help或者-h或者--help寻求帮助文档。”");
	}
}
